package Presenter;

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import Model.Game;
import View.Town.AssayView;
import View.Town.LandOfficeView;
import View.Town.PubView;
import View.Town.StoreView;
import View.Town.TownView;

/**
 * Communicates with Game to update elements in TownView
 * @author Emily Curtin
 *
 */
public class TownPresenter {
	
	public TownView townView;
	public StoreView storeView;
	public AssayView assayView;
	public LandOfficeView landOfficeView;
	public PubView pubView;
	
	
	/**
	 * Instantiates town GUI screens. Creates actionListeners for screen-navigating buttons 
	 * in the town group.
	 * @param game
	 * @param gameScreens
	 * @param allScreens
	 */
	public TownPresenter( final Game game, final CardLayout gameScreens, final MainGameScreen allScreens){
				
		townView = new TownView();
		storeView = new StoreView(game, allScreens);
		assayView = new AssayView();
		landOfficeView = new LandOfficeView();
		pubView = new PubView(game, 0, allScreens);
		
		townView.btnGoBackToMap.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent buttonClick) {
            	allScreens.getCounter().set(0);
            	gameScreens.show(allScreens.getCenterScreen(), "Map");
            }
		});
		
		townView.btnGoToStore.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent buttonClick){
				gameScreens.show(allScreens.getCenterScreen(), "StoreView");
			}
		});
		
		townView.btnGoToAssay.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent buttonClick){
				gameScreens.show(allScreens.getCenterScreen(), "AssayView");
			}
		});
		
		townView.btnGoToLand.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent buttonClick){
				gameScreens.show(allScreens.getCenterScreen(), "LandOfficeView");
			}
		});
		
		townView.btnGoToPub.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent buttonClick){
				allScreens.getRound().getTurn().endTurn();
				 
			}
		});
		
		
		class GoToTownListener implements ActionListener{
			@Override
			public void actionPerformed(ActionEvent e) {
				gameScreens.show(allScreens.getCenterScreen(), "TownView");
				
			}
		}
		
		
		storeView.btnGoToTown.addActionListener(new GoToTownListener());
		assayView.btnGoToTown.addActionListener(new GoToTownListener());
		landOfficeView.btnGoToTown.addActionListener(new GoToTownListener());

		
		allScreens.getCenterScreen().add(townView, "TownView");
		allScreens.getCenterScreen().add(storeView, "StoreView");
		allScreens.getCenterScreen().add(assayView, "AssayView");
		allScreens.getCenterScreen().add(landOfficeView, "LandOfficeView");
		allScreens.getCenterScreen().add(pubView, "pubView");

		allScreens.getCenterScreen().setLayout(gameScreens);
		
		gameScreens.addLayoutComponent(townView, "TownView");
		gameScreens.addLayoutComponent(storeView, "StoreView");
		gameScreens.addLayoutComponent(assayView, "AssayView");
		gameScreens.addLayoutComponent(landOfficeView, "LandOfficeView");
		gameScreens.addLayoutComponent(pubView, "pubView");
				
	}
}
